package cn.edu.lit.jsjxy.CourseExample.chapter5;

import android.app.Notification;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.os.Binder;
import android.os.IBinder;
import android.support.v4.app.NotificationCompat;
import android.util.Log;

import java.security.PublicKey;
import java.util.Random;

import cn.edu.lit.jsjxy.CourseExample.R;

public class MyService extends Service
{
    String TAG = this.getClass().getSimpleName();

    private DownloadBinder mBinder = new DownloadBinder();

    public MyService()
    {
    }

    @Override
    public IBinder onBind(Intent intent)
    {
        return mBinder;
    }

    @Override
    public boolean onUnbind(Intent intent)
    {
        return super.onUnbind(intent);
    }

    @Override
    public void onCreate()
    {
        super.onCreate();
        Log.d(TAG, "onCreate executed");

//        Intent intent = new Intent(this, ServiceTestActivity.class);
//        PendingIntent pi = PendingIntent.getActivity(this, 0, intent, 0);

//        Notification notification = new NotificationCompat.Builder(this)
//                .setContentTitle("This " + "is" + " content title")
//                .setContentText("This is content text")
//                .setWhen(System.currentTimeMillis())
//                .setSmallIcon(R.mipmap.ic_launcher)
//                .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
//                .setContentIntent(pi)
//                .build();
//
//        startForeground(1, notification);
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId)
    {
        Log.d(TAG, "onStartCommand executed");
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public void onDestroy()
    {
        super.onDestroy();
        Log.d(TAG, "onDestroy executed");
    }

    class DownloadBinder extends Binder
    {

        public void startDownload()
        {
            Log.d(TAG, "startDownload executed");
        }

        public int getProgress()
        {
            Log.d(TAG, "getProgress executed");
            return 0;
        }

        public  int getRandomInt(int n)
        {
            Random rnd = new Random();
            return rnd.nextInt(n);
        }
    }
}
